home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Graphics Plus
/
Graphics Plus.iso
/
general
/
viewers
/
polyview
/
polyvw31.lha
/
Polyview3.1
/
new
/
misc.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-08-24
|
4KB
|
171 lines
/* misc.c --- The "misc" commands for alvis' user interface; see ui.c */
/*---------------------------------------------------------------------------*/
#include "Xmx.h"
#include <gl/image.h>
#include <varargs.h>
/*---------------------------------------------------------------------------*/
/* GL stuff for image dumping */
typedef short sint16 ;
typedef unsigned short uint16 ;
typedef int sint32 ;
typedef unsigned int uint32 ;
typedef float flot32 ;
typedef double flot64 ;
static void lrecttoimg(char *,sint32,sint32,sint32,sint32,uint32 *) ;
static void cpacktorgba
(uint32 *l,uint16 *r,uint16 *g,uint16 *b,uint16 *a,sint32 n) ;
/* error handler for the image library */
static void rgb_err_hdlr(char *str)
{
fputs(str, stderr);
}
/*--------------------------------------------------------------------------*/
void DumpRGB(Widget w, int width, int height, char *fname)
{
static Matrix m;
static unsigned long *rgbptr;
static Boolean first_time = True;
if (first_time)
{
first_time = False;
/* set the error handler for the image library */
i_seterror(rgb_err_hdlr);
}
/* Focus on the right window. */
XmxWinset (w);
/* Save the projection matrix. */
pushmatrix ();
mmode (MPROJECTION);
getmatrix (m);
mmode (MVIEWING);
/* Save the viewport. */
pushviewport ();
readsource (SRC_FRONT);
screenspace ();
if ((rgbptr = (unsigned long *) malloc
( height * width * sizeof(unsigned long))) == 0)
{
fprintf(stderr, "Window dump malloc failed.\n");
}
else
{
lrectread (1, 1, width, height, rgbptr);
lrecttoimg (fname, 1, 1, width, height, (uint32 *)rgbptr);
}
/* Restore the projection matrix. */
mmode (MPROJECTION);
loadmatrix (m);
mmode (MVIEWING);
/* Restore the viewport. */
popviewport ();
popmatrix ();
}
/*--------------------------------------------------------------------------*/
/* ALL THIS CODE IS FOR THE RGB DUMPS -- Hacked straight from SGI demos */
/**********************************************************************
* lrecttoimg() -
**********************************************************************/
static void lrecttoimg(char *name,sint32 x1,sint32 y1,sint32 x2,sint32 y2,
uint32 *lbuf)
{
sint32 xsize, ysize, y;
IMAGE *oimage;
uint16 *rbuf, *gbuf, *bbuf, *abuf;
uint32 *save=lbuf;
xsize = x2-x1+1;
ysize = y2-y1+1;
oimage = iopen(name,"w",RLE(1),3,xsize,ysize,4);
if (!oimage)
{
return;
}
rbuf = (uint16 *)malloc(xsize*sizeof(short));
gbuf = (uint16 *)malloc(xsize*sizeof(short));
bbuf = (uint16 *)malloc(xsize*sizeof(short));
abuf = (uint16 *)malloc(xsize*sizeof(short));
for(y=0; y<ysize; y++)
{
cpacktorgba(lbuf,rbuf,gbuf,bbuf,abuf,xsize);
putrow(oimage,rbuf,y,0);
putrow(oimage,gbuf,y,1);
putrow(oimage,bbuf,y,2);
putrow(oimage,abuf,y,3);
lbuf += xsize;
}
iclose(oimage);
free(save);
free(rbuf);
free(gbuf);
free(bbuf);
}
#define CPACKTORGBA(l,r,g,b,a) \
val = (l); \
(r) = (val>>0) & 0xff; \
(g) = (val>>8) & 0xff; \
(b) = (val>>16) & 0xff; \
(a) = (val>>24) & 0xff;
/**********************************************************************
* cpacktorgba() -
**********************************************************************/
static void cpacktorgba(uint32 *l,uint16 *r,uint16 *g,uint16 *b,uint16 *a,sint32 n)
{
unsigned long val;
while(n>=8)
{
CPACKTORGBA(l[0],r[0],g[0],b[0],a[0]);
CPACKTORGBA(l[1],r[1],g[1],b[1],a[1]);
CPACKTORGBA(l[2],r[2],g[2],b[2],a[2]);
CPACKTORGBA(l[3],r[3],g[3],b[3],a[3]);
CPACKTORGBA(l[4],r[4],g[4],b[4],a[4]);
CPACKTORGBA(l[5],r[5],g[5],b[5],a[5]);
CPACKTORGBA(l[6],r[6],g[6],b[6],a[6]);
CPACKTORGBA(l[7],r[7],g[7],b[7],a[7]);
l += 8;
r += 8;
g += 8;
b += 8;
a += 8;
n -= 8;
}
while(n--)
{
CPACKTORGBA(l[0],r[0],g[0],b[0],a[0]);
l++;
r++;
g++;
b++;
a++;
}
}
/*--------------------------------------------------------------------------*/